package com.soft.servlet;


import com.soft.entity.UserInfo;
import com.soft.service.Domain;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "ForgetPasswordServlet", urlPatterns = "/ForgetPassword")
public class ForgetPasswordServlet extends HttpServlet {

    private Domain domain;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        response.setCharacterEncoding("GBK");

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        response.setCharacterEncoding("gbk");
        domain = new Domain();

        String id=request.getParameter("member.id");
        int idType= Integer.parseInt(request.getParameter("member.cardtype"));
        String idNumber=request.getParameter("member.idNumber");
        String password=request.getParameter("member.password");

        if(domain.forgetPassword(id,idType,idNumber)){
            UserInfo ui= domain.getUserInfo(id);
            ui.setPassword(password);
            domain.updateUserInfo(ui);
            request.getSession().setAttribute("flag", 7);
            request.getRequestDispatcher("/denglu.jsp").forward(request, response);
        }else{
            request.getSession().setAttribute("flag", 8);
            response.sendRedirect("/forgetPassword.jsp");
        }

    }
}
